import type { TableColumn, FormField } from '@/components'
import { reactive, ref } from 'vue'
import {newDeptTreeInfoAll} from "@/api/systemSetting/personnel";
import { competentDeptInfo } from "@/api/spotCheck/spotCheck";

competentDeptInfo().then((res) => {
  fields.value.forEach((i) => {
    if (i.key === 'competentDeptId') {
      i.attrs.data = res.data
    }
  })
})
export const fields = ref([
  {
    key: 'search',
    label: '单位名称',
    tag: 'ElInput'
  },
  {
    key: 'logout',
    label: '异常类型',
    tag: 'MSelect',
    attrs: {
      style: 'width: 210px',
      options: [
        {
          label: '未按时年检',
          value: 1
        },
        {
          label: '连续两年未年检',
          value: 2
        },
        {
          label: '未按规定成立党组织',
          value: 3
        },
        {
          label: '风险问题未销号',
          value: 4
        },
        // {
        //   label: '拟注销',
        //   value: 4
        // }
      ]
    }
  },
  {
    key: 'competentDeptId',
    label: '主管部门',
    tag: 'el-tree-select',
    placeholder: '请选择',
    attrs: {
      style: 'width: 210px',
      data: [],
      props: {
        label: 'deptName',
        value: 'deptId',
        children: 'children'
      },
      clearable: true,
      checkStrictly: true,
      filterable: true
    }
  },
  {
    key: 'types',
    label: '机构类型',
    tag: 'MSelect',
    attrs: {
      style: 'width: 210px',
      options: [
        {
          label: '民办非企业',
          value: 0
        },
        {
          label: '社会团体',
          value: 1
        }
      ]
    }
  }
])

export const columns: TableColumn[] = [
  {
    key: 'orgName',
    label: '单位名称'
  },
  {
    key: 'activityExceptionReason',
    label: '违规原因',
    width: 150
  },
  {
    key: 'legalPerson',
    label: '法定代表人',
    width: 120
  },
  {
    key: 'socialCode',
    label: '统一社会信用代码'
  },
  {
    key: 'phone',
    label: '联系电话',
    width: 140
  },
  {
    key: 'address',
    label: '地址'
  },
  {
    key: 'types',
    label: '机构类型',
    customRender: (v) => {
      let name = ''
      const type = ['民办非企业', '社会团体']
      try {
        name = type[v]
      } catch (e) {}
      return name
    },
    width: 100
  },
  {
    key: 'competentDept',
    label: '业务主管部门',
    width: 120
  },
  {
    key: 'riskMs',
    label: '风险类型',
    width: 100
  },
  {
    key: '状态',
    label: '状态',
    slot: true,
    width: 100
  },
  {
    key: 'actions',
    label: '操作',
    slot: true,
    fixed: 'right',
    width: 120
  }
]

export const dialogFields = reactive<FormField[]>([
  {
    tag: 'ElInput',
    key: 'orgName',
    label: '单位名称',
    placeholder: '请输入',
    attrs: {},
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    tag: 'ElInput',
    key: 'legalPerson',
    label: '法定代表人',
    placeholder: '请输入',
    attrs: {},
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    tag: 'ElInput',
    key: 'socialCode',
    label: '统一社会信用代码',
    placeholder: '请输入',
    attrs: {},
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    tag: 'ElInput',
    key: 'phone',
    label: '联系电话',
    placeholder: '请输入',
    attrs: {},
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    tag: 'ElInput',
    key: 'registDept',
    label: '登记部门',
    placeholder: '请输入',
    attrs: {}
  },
  {
    tag: 'el-date-picker',
    key: 'registTime',
    label: '登记时间',
    placeholder: '请选择',
    attrs: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD'
    }
  },
  {
    tag: 'ElInput',
    key: 'address',
    label: '地址',
    placeholder: '请输入',
    attrs: {},
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  },
  {
    tag: 'ElInput',
    key: 'areaCode',
    label: '单位所在地行政区划代码',
    placeholder: '请输入',
    attrs: {}
  },
  {
    tag: 'ElInput',
    key: 'zipCode',
    label: '邮编',
    placeholder: '请输入',
    attrs: {}
  },
  {
    tag: 'MRadioGroup',
    key: 'types',
    label: '机构类型',
    placeholder: '请输入',
    attrs: {
      options: [
        {
          label: '社会团体',
          value: 1
        },
        {
          label: '民办非企业',
          value: 0
        }
      ]
    },
    validateRules: [
      {
        required: true,
        message: '请选择',
        trigger: 'change'
      }
    ]
  },
  {
    tag: 'ElInput',
    key: 'economyType',
    label: '国民经济行业分类',
    placeholder: '请输入',
    attrs: {}
  },
  {
    tag: 'ElInput',
    key: 'sorgAdminType',
    label: '社会组织管理局提供分类',
    placeholder: '请输入',
    attrs: {}
  },
  {
    tag: 'MTreeSelect',
    key: 'competentDept',
    label: '业务主管部门',
    placeholder: '请选择',
    attrs: {
      data: [],
      fields: {
        label: 'deptName',
        value: 'id',
        children: 'children'
      },
      checkStrictly: true
    },
    validateRules: [
      {
        required: true,
        message: '请选择',
        trigger: 'change'
      }
    ]
  }
])
